package utils

type PageQuery struct {
	Page int
	Size int
}

func (c *PageQuery) GetOffset() int {
	offset := (c.Page - 1) * c.Size
	return offset
}

func (c *PageQuery) GetLimit() int {
	return c.Size
}

type PageResponse struct {
	Page       int `json:"page"`
	PageSize   int `json:"page_size"`
	TotalPages int `json:"total_pages"`
	TotalItems int `json:"total_items"`
}

func NewPageResponse(page int, perPage int, totalItems int) PageResponse {

	if totalItems < 1 {
		totalItems = 0
	}

	totalPages := (totalItems + perPage - 1) / perPage
	return PageResponse{
		Page:       page,
		PageSize:   perPage,
		TotalPages: totalPages,
		TotalItems: totalItems,
	}
}
